home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / Bento / BentoHdr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  11.3 KB  |  308 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        BentoHdr.cpp
  3.  
  4.     Contains:    Bento Handlers
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     5/26/95    VL        1251403: Multithreading naming support.
  13.          <1>     5/27/94    VL        first checked in
  14.  
  15.     To Do:
  16. */
  17.  
  18. #ifndef _BENTOHDR_
  19. #include "BentoHdr.h"
  20. #endif
  21.  
  22. #ifndef __CM_API__
  23. #include "CMAPI.h"
  24. #endif
  25.  
  26. #ifndef __CM_API_STDOBJIDS_
  27. #include "CMAPIIDs.h"
  28. #endif
  29.  
  30. #ifndef __STRING__
  31. #include "string.h"                // for strcmp
  32. #endif
  33.  
  34. #pragma segment BentoHdr
  35.  
  36. //==============================================================================
  37. // Function Prototype
  38. //==============================================================================
  39.  
  40.      CM_CFUNCTIONS
  41.  
  42. CMHandlerAddr CM_FIXEDARGS containerMetahandler(CMType targetType, CMconst_CMGlobalName operationType);
  43.                                                                 
  44. static CMRefCon open_Handler(CMRefCon attributes, CMOpenMode mode);
  45. static void close_Handler(CMRefCon refCon);
  46. static CMSize flush_Handler(CMRefCon refCon);
  47. static CMSize seek_Handler(CMRefCon refCon, CM_LONG posOff, CMSeekMode mode);
  48. static CMSize tell_Handler(CMRefCon refCon);
  49. static CMSize read_Handler(CMRefCon refCon, CMPtr buffer, CMSize elementSize, CMCount theCount);
  50. static CMSize write_Handler(CMRefCon refCon, CMPtr buffer, CMSize elementSize, CMCount theCount);
  51. static CMEofStatus eof_Handler(CMRefCon refCon);
  52. static CMBoolean trunc_Handler(CMRefCon refCon, CMSize containerSize);
  53. static CMSize containerSize_Handler(CMRefCon refCon);
  54. static void readLabel_Handler(CMRefCon refCon, CMMagicBytes magicByteSequence,
  55.                             CMContainerFlags *flags, CM_USHORT *bufSize,
  56.                             CM_USHORT *majorVersion, CM_USHORT *minorVersion,
  57.                             CMSize *tocOffset, CMSize *tocSize);
  58. static void writeLabel_Handler(CMRefCon refCon, CMMagicBytes magicByteSequence,
  59.                             CMContainerFlags flags, CM_USHORT bufSize,
  60.                             CM_USHORT majorVersion, CM_USHORT minorVersion,
  61.                             CMSize tocOffset, CMSize tocSize);    
  62. static CMValue returnParentValue_Handler(CMRefCon refCon);
  63. static CM_UCHAR *returnContainerName_Handler(CMRefCon refCon);
  64. static CMType returnTargetType_Handler(CMRefCon refCon, CMContainer container);    
  65. static void extractData_Handler(CMRefCon refCon, CMDataBuffer buffer,
  66.                                  CMSize size, CMPrivateData data);
  67. static void formatData_Handler(CMRefCon refCon, CMDataBuffer buffer,
  68.                                 CMSize size, CMPrivateData data);
  69.                                                                  
  70.     CM_END_CFUNCTIONS
  71.  
  72. //------------------------------------------------------------------------------
  73. // containerMetahandler
  74. //------------------------------------------------------------------------------
  75. CMHandlerAddr CM_FIXEDARGS containerMetahandler(CMType targetType, CMconst_CMGlobalName operationType)
  76. {
  77.     static char *operationTypes[] = {CMOpenOpType,                        /*  0 */
  78.                                      CMCloseOpType,                        /*  1 */
  79.                                      CMFlushOpType,                        /*  2 */
  80.                                      CMSeekOpType,                        /*  3 */
  81.                                      CMTellOpType,                        /*  4 */
  82.                                      CMReadOpType,                        /*  5 */
  83.                                      CMWriteOpType,                        /*  6 */
  84.                                      CMEofOpType,                        /*  7 */
  85.                                      CMTruncOpType,                        /*  8 */
  86.                                      CMSizeOpType,                        /*  9 */
  87.                                      CMReadLblOpType,                    /* 10 */
  88.                                      CMWriteLblOpType,                    /* 11 */
  89.                                      CMParentOpType,                    /* 12 */
  90.                                      CMContainerOpName,                    /* 13 */
  91.                                      CMTargetTypeOpType,                /* 14 */
  92.                                      CMExtractDataOpType,                /* 15 */
  93.                                      CMFormatDataOpType,                /* 16 */
  94.                                      NULL};
  95.     char      **t;
  96.     CMType ignored = targetType;
  97.         
  98.     t = operationTypes - 1;
  99.     while (*++t) if (strcmp((char *)operationType, *t) == 0) break;
  100.     
  101.     switch (t - operationTypes) {
  102.         case  0:    return ((CMHandlerAddr)open_Handler);                /*CMOpenOpType             */
  103.         case  1:    return ((CMHandlerAddr)close_Handler);                /*CMCloseOpType         */
  104.         case  2:    return ((CMHandlerAddr)flush_Handler);                /*CMFlushOpType         */
  105.         case  3:    return ((CMHandlerAddr)seek_Handler);                /*CMSeekOpType             */
  106.         case  4:    return ((CMHandlerAddr)tell_Handler);                /*CMTellOpType             */
  107.         case  5:    return ((CMHandlerAddr)read_Handler);                /*CMReadOpType             */
  108.         case  6:    return ((CMHandlerAddr)write_Handler);                /*CMWriteOpType         */
  109.         case  7:    return ((CMHandlerAddr)eof_Handler);                /*CMEofOpType             */
  110.         case  8:    return ((CMHandlerAddr)trunc_Handler);                /*CMTruncOpType            */
  111.         case  9:    return ((CMHandlerAddr)containerSize_Handler);        /*CMSizeOpType             */
  112.         case 10:    return ((CMHandlerAddr)readLabel_Handler);            /*CMReadLblOpType         */
  113.         case 11:    return ((CMHandlerAddr)writeLabel_Handler);            /*CMWriteLblOpType         */
  114.         case 12:    return ((CMHandlerAddr)returnParentValue_Handler);    /*CMParentOpType        */
  115.         case 13:    return ((CMHandlerAddr)returnContainerName_Handler);/*CMContainerOpName        */
  116.         case 14:    return ((CMHandlerAddr)returnTargetType_Handler);    /*CMTargetTypeOpType    */
  117.         case 15:    return ((CMHandlerAddr)extractData_Handler);        /*CMExtractDataOpType    */
  118.         case 16:    return ((CMHandlerAddr)formatData_Handler);         /*CMFormatDataOpType    */
  119.         
  120.         default:    return (NULL);
  121.     }
  122. }
  123.  
  124. //------------------------------------------------------------------------------
  125. // open_Handler
  126. //------------------------------------------------------------------------------
  127. static CMRefCon open_Handler(CMRefCon refCon, CMOpenMode mode)
  128. {
  129.     return ((ODBentoHandlers*) refCon)->OpenHandler(mode);
  130. }
  131.  
  132. //------------------------------------------------------------------------------
  133. // close_Handler
  134. //------------------------------------------------------------------------------
  135. static void close_Handler(CMRefCon refCon)
  136. {
  137.     ((ODBentoHandlers*) refCon)->CloseHandler();
  138. }
  139.  
  140. //------------------------------------------------------------------------------
  141. // flush_Handler
  142. //------------------------------------------------------------------------------
  143. static CMSize flush_Handler(CMRefCon refCon)
  144. {
  145.     return ((ODBentoHandlers*) refCon)->FlushHandler();
  146. }
  147.  
  148. //------------------------------------------------------------------------------
  149. // seek_Handler
  150. //------------------------------------------------------------------------------
  151. static CMSize seek_Handler(CMRefCon refCon, CM_LONG posOff, CMSeekMode mode)
  152. {
  153.     return ((ODBentoHandlers*) refCon)->SeekHandler(posOff, mode);
  154.  
  155. }
  156.  
  157. //------------------------------------------------------------------------------
  158. // tell_Handler
  159. //------------------------------------------------------------------------------
  160. static CMSize tell_Handler(CMRefCon refCon)
  161. {
  162.     return     ((ODBentoHandlers*) refCon)->TellHandler();
  163. }
  164.  
  165. //------------------------------------------------------------------------------
  166. // read_Handler
  167. //------------------------------------------------------------------------------
  168. static CMSize read_Handler(CMRefCon refCon,
  169.                             CMPtr buffer,
  170.                             CMSize elementSize,
  171.                             CMCount theCount)
  172. {
  173.     return ((ODBentoHandlers*) refCon)->ReadHandler(buffer, elementSize, theCount);
  174. }
  175.  
  176. //------------------------------------------------------------------------------
  177. // write_Handler
  178. //------------------------------------------------------------------------------
  179. static CMSize write_Handler(CMRefCon refCon,
  180.                             CMPtr buffer,
  181.                             CMSize elementSize,
  182.                             CMCount theCount)
  183. {
  184.     return     ((ODBentoHandlers*) refCon)->WriteHandler(buffer, elementSize, theCount);
  185. }
  186.  
  187. //------------------------------------------------------------------------------
  188. // eof_Handler
  189. //------------------------------------------------------------------------------
  190. static CMEofStatus eof_Handler(CMRefCon refCon)
  191. {
  192.     return     ((ODBentoHandlers*) refCon)->EOFHandler();
  193.  
  194. }
  195.  
  196. //------------------------------------------------------------------------------
  197. // trunc_Handler
  198. //------------------------------------------------------------------------------
  199. static CMBoolean trunc_Handler(CMRefCon refCon, CMSize containerSize)
  200. {
  201.     return ((ODBentoHandlers*) refCon)->TruncHandler(containerSize);
  202. }
  203.  
  204. //------------------------------------------------------------------------------
  205. // containerSize_Handler
  206. //------------------------------------------------------------------------------
  207. static CMSize containerSize_Handler(CMRefCon refCon)
  208. {
  209.     return ((ODBentoHandlers*) refCon)->ContainerSizeHandler();
  210.  
  211. }
  212.  
  213. //------------------------------------------------------------------------------
  214. // readLabel_Handler
  215. //------------------------------------------------------------------------------
  216. static void readLabel_Handler(CMRefCon refCon,
  217.                                 CMMagicBytes magicByteSequence,
  218.                                 CMContainerFlags *flags,
  219.                                 CM_USHORT *bufSize,
  220.                                 CM_USHORT *majorVersion,
  221.                                 CM_USHORT *minorVersion,
  222.                                 CMSize *tocOffset,
  223.                                 CMSize *tocSize)
  224. {
  225.     ((ODBentoHandlers*) refCon)->ReadLabelHandler(magicByteSequence, flags, bufSize,
  226.                                             majorVersion, minorVersion,
  227.                                             tocOffset, tocSize);
  228. }
  229.  
  230. //------------------------------------------------------------------------------
  231. // writeLabel_Handler
  232. //------------------------------------------------------------------------------
  233. static void writeLabel_Handler(CMRefCon refCon,
  234.                                 CMMagicBytes magicByteSequence,
  235.                                 CMContainerFlags flags,
  236.                                 CM_USHORT bufSize,
  237.                                 CM_USHORT majorVersion,
  238.                                 CM_USHORT minorVersion,
  239.                                 CMSize tocOffset,
  240.                                 CMSize tocSize)
  241. {
  242.     ((ODBentoHandlers*) refCon)->WriteLabelHandler(magicByteSequence,
  243.                                             flags, bufSize,
  244.                                             majorVersion, minorVersion,
  245.                                             tocOffset, tocSize);
  246. }
  247.  
  248. //------------------------------------------------------------------------------
  249. // returnParentValue_Handler
  250. //------------------------------------------------------------------------------
  251. static CMValue returnParentValue_Handler(CMRefCon refCon)
  252. {
  253.     return ((ODBentoHandlers*) refCon)->ReturnParentValueHandler();
  254. }
  255.  
  256. //------------------------------------------------------------------------------
  257. // returnContainerName_Handler
  258. //------------------------------------------------------------------------------
  259. static CM_UCHAR *returnContainerName_Handler(CMRefCon refCon)
  260. {
  261.     return ((ODBentoHandlers*) refCon)->ReturnContainerNameHandler();
  262. }
  263.  
  264. //------------------------------------------------------------------------------
  265. // returnTargetType_Handler
  266. //------------------------------------------------------------------------------
  267. static CMType returnTargetType_Handler(CMRefCon refCon, CMContainer container)
  268. {
  269.     return ((ODBentoHandlers*) refCon)->ReturnTargetTypeHandler(container);
  270. }
  271.  
  272. //------------------------------------------------------------------------------
  273. // extractData_Handler
  274. //------------------------------------------------------------------------------
  275. static void extractData_Handler(CMRefCon refCon,
  276.                                 CMDataBuffer buffer,
  277.                                 CMSize size,
  278.                                 CMPrivateData data)
  279. {
  280.     ((ODBentoHandlers*) refCon)->ExtractDataHandler(buffer, size, data);
  281. }
  282.  
  283. //------------------------------------------------------------------------------
  284. // formatData_Handler
  285. //------------------------------------------------------------------------------
  286. static void formatData_Handler(CMRefCon refCon,
  287.                                 CMDataBuffer buffer,
  288.                                 CMSize size,
  289.                                 CMPrivateData data)
  290. {
  291.     ((ODBentoHandlers*) refCon)->FormatDataHandler(buffer, size, data);
  292. }
  293.  
  294. //------------------------------------------------------------------------------
  295. // ODBentoHandlers::ODBentoHandlers
  296. //------------------------------------------------------------------------------
  297. ODBentoHandlers::ODBentoHandlers()
  298. {
  299. }
  300.  
  301. //------------------------------------------------------------------------------
  302. // ODBentoHandlers::~ODBentoHandlers
  303. //------------------------------------------------------------------------------
  304. ODBentoHandlers::~ODBentoHandlers()
  305. {
  306. }
  307.  
  308.